import {
  BackgroundMode,
  Camera,
  Vector3,
  WebGLEngine,
  Logger,
  DirectLight,
} from "oasis-engine";
import { GameScript } from "./game";
import { RoleScript } from "./role";
import { CameraScript } from "./scene/camera";
import { SceneScript } from "./scene/scene";

Logger.enable();

const engine = new WebGLEngine("canvas");
engine.canvas.resizeByClientSize();
console.log(engine);
const scene = engine.sceneManager.activeScene;
scene.background.mode = BackgroundMode.SolidColor;
scene.background.solidColor.setValue(208 / 255, 210 / 255, 211 / 255, 1);
scene.ambientLight.diffuseSolidColor.setValue(1, 1, 1, 1);
scene.ambientLight.diffuseIntensity = 0.5;
``;
const rootEntity = scene.createRootEntity();
rootEntity.createChild("ground");
const cameraEntity = rootEntity.createChild("camera");
const camera = cameraEntity.addComponent(Camera);
cameraEntity.addComponent(CameraScript);

rootEntity.createChild("role").addComponent(RoleScript);

rootEntity.addComponent(SceneScript);
rootEntity.addComponent(GameScript);

// init camera
camera.isOrthographic = true;
camera.orthographicSize = 60;
camera.nearClipPlane = 0.1;
camera.farClipPlane = 1000;
cameraEntity.transform.lookAt(new Vector3(0, 0, 0));

const directLightEntity = rootEntity.createChild("directLight");
const directLight = directLightEntity.addComponent(DirectLight);
directLight.intensity = 0.5;
directLightEntity.transform.setPosition(10, 30, 20);
directLightEntity.transform.lookAt(new Vector3(0, 0, 0));

engine.run();
